Imports System.ComponentModel
Imports System.Web.HttpContext

<DataObject(True)> _
Public Class QuestionODS

#Region "For Queston"

    <DataObjectMethod(DataObjectMethodType.Insert, True)> _
    Public Shared Function CreateQuestion( _
    ByVal categoryId As Integer, _
    ByVal question As String, _
    ByVal configuration As String, _
    Optional ByVal choices As DataView = Nothing) As Question

        If Current.User.IsInRole("QuestionnaireManagers") _
        OrElse Current.User.IsInRole("QuestionnaireAdmins") Then
            Return QuestionnaireODS.Provider.CreateQuestion(categoryId, question, configuration, choices)
        Else
            Throw New Exception("You have no right to create a question.")
        End If
    End Function

    <DataObjectMethod(DataObjectMethodType.Delete, True)> _
    Public Shared Sub DeleteQuestion(ByVal original_ID As Integer)
        'Throw New Exception("The value passed to the delete method is " & original_ID)
        If Current.User.IsInRole("QuestionnaireAdmins") Then
            QuestionnaireODS.Provider.DeleteQuestion(original_ID)
        Else
            Throw New Exception("You have no right to delete a question.")
        End If
    End Sub

    Public Shared Function GetChoices(ByVal id As Integer) As DataTable
        Return QuestionnaireODS.Provider.GetChoices(id)
    End Function

    <DataObjectMethod(DataObjectMethodType.Select, True)> _
    Public Shared Function GetQuestions( _
    ByVal CategoryID As Integer, _
    ByVal StringToSearch As String) As DataView
        Return QuestionnaireODS.Provider.GetQuestions(CategoryID, StringToSearch)
    End Function

    Public Shared Function GetQuestion(ByVal id As Integer) As Question
        Return QuestionnaireODS.Provider.GetQuestion(id)
    End Function

    <DataObjectMethod(DataObjectMethodType.Update, True)> _
    Public Shared Sub UpdateQuestion( _
    ByVal id As Integer, _
    ByVal categoryId As Integer, _
    ByVal question As String, _
    ByVal configuration As String, _
    Optional ByVal choices As DataView = Nothing)
        If Current.User.IsInRole("QuestionnaireManagers") _
        OrElse Current.User.IsInRole("QuestionnaireAdmins") Then
            Dim _question As New Question(id, categoryId, question, configuration)
            QuestionnaireODS.Provider.UpdateQuestion(_question, choices)
        Else
            Throw New Exception("You have no right to update a question.")
        End If
    End Sub

#End Region

End Class
